package com.joinway.mobile.service

import java.util.List;

import javax.annotation.PostConstruct

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional

import com.joinway.framework.data.jdbc.repository.TableRepository
import com.joinway.mobile.bean.Product
import com.joinway.mobile.bean.form.OrderForm;
import com.joinway.mobile.bean.view.OrderProduct
import com.joinway.mobile.bean.view.ShopCartProduct;
import com.joinway.mobile.constants.AppConstants

@Service("agriService")
class AgriService implements JiayidaService {

	@Autowired @Qualifier("agriRepository") protected TableRepository repository
	
	protected JiayidaServiceSupport service;
	
	@PostConstruct public void init(){
		service = new JiayidaServiceSupport(AppConstants.TablePrefix.Agriculture, repository)
	}
	
	@Transactional(value="agriTransactionManager",readOnly=true)
	@Override
	public List<Product> getProducts(Integer catId, int page, int rows) throws Exception {
		return service.getProducts(catId, page, rows);
	}

	@Transactional(value="agriTransactionManager",readOnly=true)
	@Override
	public Product getProductDetail(int id) throws Exception {
		return service.getProductDetail(id);
	}

	@Transactional(value="agriTransactionManager",readOnly=true)
	@Override
	public List<OrderProduct> getOrderedProducts(int userId, int page, int rows) throws Exception {
		return service.getOrderedProducts(userId, page, rows);
	}

	@Transactional(value="agriTransactionManager",readOnly=true)
	@Override
	public List<ShopCartProduct> getShopCartProduct(int userId, int page, int rows) throws Exception {
		return service.getShopCartProduct(userId, page, rows);
	}

	@Transactional(value="agriTransactionManager",rollbackFor=Throwable.class)
	@Override
	public void deleteShopCart(int cartId) throws Exception {
		service.deleteShopCart(cartId)
	}

	@Transactional(value="agriTransactionManager",rollbackFor=Throwable.class)
	@Override
	public void addShopCart(int userId, int pid, String propId, int number) throws Exception {
		service.addShopCart(userId, pid, propId, number)
	}

	@Transactional(value="agriTransactionManager",rollbackFor=Throwable.class)
	@Override
	public void updateShopCart(int cartId, int number) throws Exception {
		service.updateShopCart(cartId, number)
	}

	@Transactional(value="agriTransactionManager",rollbackFor=Throwable.class)
	@Override
	public void addOrder(String orderStr, String goodsList, String cartIds) throws Exception {
		service.addOrder(orderStr, goodsList, cartIds)
	}

	@Transactional(value="agriTransactionManager",rollbackFor=Throwable.class)
	@Override
	public void createOrder(OrderForm userOrder) throws Exception{
		service.createOrder(userOrder)
	}
}
